<template>
  <div class="login">
    <h3>{{ baseURL }}</h3>
    <el-card>
      <img class="img" src="@/assets/logo.png" alt="" />
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item prop="mobile">
          <el-input placeholder="请输入手机号" v-model="form.mobile"></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input
            placeholder="请输入验证码"
            v-model="form.code"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item prop="check">
          <el-checkbox v-model="form.check"
            >我已阅读并同意「用户协议」和「隐私条款」</el-checkbox
          >
        </el-form-item>
        <el-form-item>
          <el-button class="btn" type="primary" @click="submit">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data () {
    return {
      baseURL: process.env.VUE_APP_URL,
      mobile: '13200000000',
      code: '246810',
      form: {
        mobile: '',
        code: '',
        check: false
      },
      rules: {
        mobile: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入11位手机号', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('请正确输入手机号！'))
              }
            }
          }
        ],
        code: [
          { required: true, message: '必填', trigger: 'blur' },
          {
            min: 4,
            max: 4,
            message: '请输入4位验证码',
            trigger: 'blur'
          }
        ],
        check: [
          { required: true, message: '必填', trigger: 'change' },
          {
            validator: (rule, value, callback) => {
              if (value) {
                callback()
              } else {
                callback(new Error('必选项'))
              }
            },
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    submit () {
      this.$refs.form.validate(res => {
        if (res) {
          this.$message.success('验证成功')
        } else {
          this.$message.error('验证失败')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.login {
  height: 100%;
  background-image: url(~@/assets/login.png);
  background-size: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .el-card {
    width: 460px;
    .img {
      display: block;
      width: 200px;
      margin: 0 auto;
    }
    .btn {
      width: 100%;
    }
  }
}
// 加了scoped el-card内部看不到的 管不到需要加::v-deep 才可以设置他的样式
// 浏览器兼容问题写法：>>> /deep/
::v-deep .el-card__body {
  padding: 20px 40px;
}
</style>
